@extends('admin.main')
@section('head')
    @include('UEditor::head')
@endsection
@section('body')
    <div class="main-title">
        <h2>{{isset($info['pid']) ? '编辑':'新增'}}菜单</h2>
    </div>
    <div class="tab-wrap">
        <div class="tab-content">
            <form action="" method="post" class="form-horizontal">
                <!-- 基础 -->
                <div id="tab1" class="tab-pane in tab1">
                    <div class="form-item">
                        <label class="item-label">上级菜单<span class="check-tips">（所属的上级菜单）</span></label>
                        <div class="controls">
                            <select name="pid" id="menu_pid">
                                @if(count($menu))
                                    @foreach($menu as $v)
                                        <option value="{{$v['id']}}"
                                                @if(isset($info['pid']) && $info['pid'] == $v['id']) selected @endif>{{$v['prefix']}}{{$v['title']}}</option>
                                    @endforeach
                                @endif
                            </select>
                        </div>
                    </div>
                    <div class="form-item">
                        <label class="item-label">
                            菜单名称<span class="check-tips">（名称不能为空,最多6个字）</span>
                        </label>
                        <div class="controls">
                            <input type="text" name="title" class="text input-large"
                                   value="{{isset($info['title']) ? $info['title'] : ''}}">
                        </div>
                    </div>
                    <div id="prime">
                        <div class="form-item">
                            <label class="item-label">
                                菜单类型<span class="check-tips"></span>
                            </label>
                            <div class="controls">
                                <label class="inline radio"><input type="radio" name="type" value="1"
                                                                   @if(!isset($info['type']) || $info['type'] == 1) checked @endif>发送消息</label>
                                <label class="inline radio"><input type="radio" name="type" value="2"
                                                                   @if(isset($info['type']) &&  $info['type'] == 2) checked @endif>跳转网页</label>
                                <label class="inline radio"><input type="radio" name="type" value="3"
                                                                   @if(isset($info['type']) &&  $info['type'] == 3) checked @endif>跳转小程序</label>
                            </div>
                        </div>
                        <div id="type_1">
                            {{--<div class="form-item">--}}
                                {{--<label class="item-label">--}}
                                    {{--关键词<span class="check-tips">（关键词不能为空,最多6个字）</span>--}}
                                {{--</label>--}}
                                {{--<div class="controls">--}}
                                    {{--<input type="text" name="keyword" class="text input-small"--}}
                                           {{--value="{{isset($info['keyword']) ? $info['keyword'] : ''}}">--}}
                                {{--</div>--}}
                            {{--</div>--}}
                            <div class="form-item">
                                <label class="item-label">消息文本</label>
                                <div class="controls">
                                    <textarea name="reply_content" id="reply_content" cols="100" rows="13">{{ isset($info['reply_content']) ? "{$info['reply_content']}" : "" }}</textarea>
                                </div>
                            </div>
                        </div>
                        <div id="type_2" style="display: none">
                            <div class="form-item">
                                <label class="item-label">
                                    菜单URL链接<span class="check-tips">（链接不能为空,必须是以http://打头的完整链接）</span>
                                </label>
                                <div class="controls">
                                    <input type="text" name="url" id="url" class="text input-large"
                                           value="{{isset($info['url']) ? $info['url'] : ''}}">
                                    <p>
                                        从功能库选择:
                                        <select name="fun" id="fun">
                                            <option value="">自定义链接</option>
                                            @foreach($modules as $v)
                                                <option value="{{url($v['url'])}}">{{$v['title']}}</option>
                                            @endforeach
                                        </select>
                                    </p>
                                </div>
                            </div>
                        </div>
                        <div id="type_3" style="display: none">
                            <div class="form-item">
                                <label class="item-label">
                                    小程序路径<span class="check-tips">（路径不能为空,必须是以pages/打头的完整链接,例如：pages/index/index）</span>
                                </label>
                                <div class="controls">
                                    <input type="text" name="pagepath" id="pagepath" class="text input-large"
                                           value="{{isset($info['pagepath']) ? $info['pagepath'] : ''}}">
                                </div>
                            </div>
                            <div class="form-item">
                                <label class="item-label">
                                    选择小程序<span class="check-tips"></span>
                                </label>
                                <div class="controls">
                                    <select name="appid">
                                        @foreach($xcx as $v)
                                            <option value="{{$v['appid']}}" @if(isset($info['appid']) && $info['appid'] == $v['appid']) selected @endif>{{$v['title']}}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                            <div class="form-item">
                                <label class="item-label">
                                    备用网址<span class="check-tips">（不支持小程序的老版本客户端将打开本网址,必须是以http://打头的完整链接）</span>
                                </label>
                                <div class="controls">
                                    <input type="text" name="bak_url"  id="bak_url" class="text input-large"
                                           value="{{isset($info['url']) ? $info['url'] : ''}}">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-item">
                        <label class="item-label">
                            显示<span class="check-tips"></span>
                        </label>
                        <div class="controls">
                            <label class="inline radio"><input type="radio" name="is_show" value="1"
                                                               @if(!isset($info['is_show']) ||  $info['is_show'] == 1) checked @endif>是</label>
                            <label class="inline radio"><input type="radio" name="is_show" value="0"
                                                               @if(isset($info['is_show']) && $info['is_show'] == 0) checked @endif>否</label>
                        </div>
                    </div>
                </div>
                <div class="form-item">
                    <input type="hidden" name="id" value="{{isset($info['id']) ? $info['id'] : ''}}">
                    <input type="hidden" name="old_pid" value="{{isset($info['pid']) ? $info['pid'] : ''}}">
                    <button type="submit" id="submit" class="btn submit-btn ajax-post" target-form="form-horizontal">确
                        定
                    </button>
                    <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
                </div>
            </form>
        </div>
    </div>
@endsection
@section('script')
    <script type="text/javascript">
        $("#fun").change(function(){
            var url = $(this).val();
            $("#url").val(url);
            if(url != ''){
                $("#url").attr("readonly",'readonly');
            } else {
                $("#url").removeAttr("readonly");
            }

        });
        {{--var pid = parseInt("{{isset($info['pid']) ? $info['pid'] : 0}}");--}}

        {{--if (!pid) {--}}
            {{--$("#prime").hide();--}}
        {{--}--}}

        {{--$("#menu_pid").change(function () {--}}
            {{--var pid = parseInt($(this).val());--}}
            {{--if (!pid) {--}}
                {{--$("#prime").hide();--}}
            {{--} else {--}}
                {{--$("#prime").show();--}}
            {{--}--}}
        {{--});--}}

        var type = parseInt("{{isset($info['type']) ? $info['type'] : 0}}");
        showType(type);
        $("input[name=type]").each(function () {
            $(this).change(function () {
                type = parseInt($(this).val());
                showType(type);
            });

        });

        function showType(type) {
            switch (type) {
                case 1:
                    $("#type_1").show();
                    $("#type_2").hide();
                    $("#type_3").hide();
                    break;
                case 2:
                    $("#type_1").hide();
                    $("#type_2").show();
                    $("#type_3").hide();
                    break;
                case 3:
                    $("#type_1").hide();
                    $("#type_2").hide();
                    $("#type_3").show();
                    break;
            }
        }
    </script>
@endsection
